package co.atguigu.es;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

/**
 * @author LiuYunXin
 * @create 2022-06-02-0:07
 */
@RunWith(SpringRunner.class)
@SpringBootTest
public class SpringDataESProductDaoTest {
    @Autowired
    private ProductDao productDao;

    @Test
    public void save(){
        Product product = new Product();
        product.setId(2L);
        product.setTitle("华为");
        product.setCategory("shouji");
        product.setPrice(2000.0);
        product.setImages("http://www.atguigu/hw.jpg");
        productDao.save(product);
    }

    @Test
    public void update(){
        // id相同 则执行更新
        Product product = new Product();
        product.setId(2L);
        product.setTitle("华为2");
        product.setCategory("shouji2");
        product.setPrice(200022.0);
        product.setImages("http://www.atguigu/hw.jpg");
        productDao.save(product);
    }

    @Test
    public void findById(){
        Product product = productDao.findById(2L).get();
        System.out.println(product);
    }

    @Test
    public void findAll(){
        Iterable<Product> all = productDao.findAll();
        for (Product product : all) {
            System.out.println(product);
        }
    }
}
